<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:include="base/head::head"/>
<!--角色业务权限点-->
<body class="easyui-layout" data-options="border:false">
<div th:replace="base/load::load"/>
<div id="table-permission-tool">
    <a id="btn-ok" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="onSaveRolePermission()">保存</a>
    <a id="btn-refresh" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-refresh',plain:true" onclick="onRolePermissionRefresh()">刷新</a>
</div>
<div data-options="region:'west',split:true,title:'角色列表'" style="width:160px;">
    <ul id="role" class="easyui-datalist" data-options="url:'../role/list',valueField:'id',textField:'roleDisplay',method:'get',animate:true,border:false,onClickRow:onListItemClick"></ul>
</div>
<div id="main" region="center" data-options="border:false" style="overflow: hidden;">
    <div class="easyui-layout" data-options="fit:true,border:false">
        <div data-options="region:'center',title:'业务列表',border:false">
            <table id="biz" class="easyui-datagrid" data-options="url:'../form/list?formStatus=1',method:'get',fit:true,singleSelect:true,rownumbers:true,onClickRow:onBizClickRow">
                <thead>
                <th data-options="field:'id',checkbox:true"></th>
                <th data-options="field:'formDisplay',width:200">名称</th>
                <th data-options="field:'formName',width:200">标识</th>
                <th data-options="field:'formComment'">备注</th>
                </thead>
            </table>
        </div>
        <div data-options="region:'south',title:'权限点',height:600">
            <table id="permission" class="easyui-datagrid" data-options="fit:true,singleSelect:false,rownumbers:true,toolbar:'#table-permission-tool'">
                <thead>
                <th data-options="field:'id',checkbox:true"></th>
                <th data-options="field:'formName',width:100">名称</th>
                <th data-options="field:'formOperation',width:100">标识</th>
                </thead>
            </table>
        </div>
    </div>
</div>
<script type="text/javascript">

    function onListItemClick(index, node) {
        $("#biz").datagrid("clearSelections");
        $("#permission").datagrid("clearSelections");
        $("#permission").datagrid("loadData", []);
    }

    function onBizClickRow(index, row) {
        formPermission();
    }

    function formPermission() {
        // 获取角色
        var roleVO = $("#role").datalist("getSelected");
        if (roleVO == null) {
            AlertUtil.error("请选择角色后，在操作！");
            return;
        }

        var formVO = $("#biz").datagrid("getSelected");
        if (formVO == null) {
            AlertUtil.error("请选择业务表格后，在操作！");
            return;
        }
        getFormPermission(roleVO.id, formVO.formName)
    }

    // 获取业务表单权限点
    function getFormPermission(rid, formName) {
        if (formName == null || formName == "") {
            return;
        }

        $("#permission").datagrid({
            "url": "../permission/fr?rid=" + rid + "&fn=" + formName,
            "method": "get"
        })
    }

    function onSaveRolePermission() {
        // 获取角色
        var roleVO = $("#role").datalist("getSelected");
        if (roleVO == null) {
            AlertUtil.error("请选择角色后，在操作！");
            return;
        }

        // 获取权限点列表
        var rows = $("#permission").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            AlertUtil.warning("请选择后，再操作！");
            return;
        }

        var str = JSON.stringify(rows)

        AjaxUtil.post("rp", {"rid": roleVO.id, "fn": rows[0].formName, "rps": str}, function (data) {
            AlertUtil.info(data.msg)
        });
    }

    function onRolePermissionRefresh() {
        $("#permission").datagrid("clearSelections");
        $("#permission").datagrid("reload");
    }


</script>
</body>
</html>

